import axiosIns from './axiosIns'
import timeout from './error.js'
import url from './config'
const errMsg = 'tomcat原地爆炸了'

export default {
  getUserDatas () {
    return new Promise((resolve, reject) => {
      axiosIns.get(`${url}/user/list`)
        .then(data => {
          if (data.data.success === true) {
            resolve(data.data.data)
          } else {
            reject(data.data.message)
          }
        })
        .catch(() => {
          reject(errMsg)
        })
      timeout(reject)
    })
  },
  deleteUser (params) {
    return new Promise((resolve, reject) => {
      axiosIns.delete(`${url}/user/delete/${params}`)
        .then(data => {
          if (data.data.data.success === true) {
            resolve()
          } else {
            reject(data.data.data.message)
          }
        })
        .catch(() => {
          reject(errMsg)
        })
      timeout(reject)
    })
  },
  addUser (params) {
    return new Promise((resolve, reject) => {
      axiosIns.post(`${url}/user/add`, params)
        .then(data => {
          if (data.data.data.success === true) {
            resolve()
          } else {
            reject(data.data.data.message)
          }
        })
        .catch(() => {
          reject(errMsg)
        })
      timeout(reject)
    })
  }
}
